using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SMS.Framework;

namespace SMS.MdiWindow.Modules
{
    public partial class ucNewMessage : UserControl
    {
        public ucNewMessage()
        {
            InitializeComponent();
            Context.Current.OnApplicationCommand += new OnApplicationCommandEventHandler(Current_OnApplicationCommand);
        }

        bool Current_OnApplicationCommand(object sender, string commandName, object[] commandParameters)
        {
            switch (commandName.ToLower())
            {
                case "updatemessagelistbox":
                    ucNewMessage_Load(null, null);
                    break;
            }
            return true;
        }

        private void lblCaption_DoubleClick(object sender, EventArgs e)
        {

            if (this.Height == 125)
                this.Minimize();
            else
                this.Maximize();
        }

        public void Maximize()
        {
            this.Height = 125;
        }
        public void Minimize()
        {
            this.Height = 20;
        }

        private void lblCaption_Click(object sender, EventArgs e)
        {

            if (this.Height == 125)
                this.Minimize();
            else
                this.Maximize();
        }

        private void ucNewMessage_Load(object sender, EventArgs e)
        {
            lstMessage.Items.Clear();
            List<MessageEntry> entries = DataAccess.GetNewMessageEntries();
            foreach (MessageEntry entry in entries)
            {
                lstMessage.Items.Add(entry.MessageId);
            }
        }

        private void lstMessage_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        private void lstMessage_Click(object sender, EventArgs e)
        {
        }

        private void lstMessage_SelectedValueChanged(object sender, EventArgs e)
        {
            MessageForm msgForm = new MessageForm();
            msgForm.Tag = lstMessage.SelectedItems[0].ToString();

            msgForm.ShowDialog();
        }
    }
}
